﻿@using SCMS.Resources
@model IEnumerable<SCMS.Model.MBCategory>
@if (Model.Count() < 1)
{ 
    <br /><font color="red">@string.Format(Resources_frank.MasterBudget_MasterBudget_NoExchangeRate, ViewBag.Currency)</font>
}

    <table width="98%" align="center" cellspacing="0" cellpadding="5" border="1" style="border: 1px solid grey;
            border-collapse: collapse; padding: 5px; font-size: 12px;">
        <tr>
            <th colspan="3" rowspan="2" align="center" valign="middle">
                <h3>@Resources_frank.Global_String_MasterBudgetCurrency (@ViewBag.Currency)</h3>
            </th>
            <th colspan="8" align="center" class="gridheader">
                @Resources_frank.Global_String_GrandTotals.ToUpper()
            </th>
        </tr>
        <tr>
            <td align="right">
                <b>@Html.DisplayFor(m => Model.ToList()[Model.Count() - 1].TotalBudget)</b>
            </td>
            <td align="right">
                <b>@Html.DisplayFor(m => Model.ToList()[Model.Count() - 1].TotalCommitted)</b>
            </td>
            <td align="right">
                <b>@Html.DisplayFor(m => Model.ToList()[Model.Count() - 1].TotalPosted)</b>
            </td>
            <td align="right">
                <b>@Html.DisplayFor(m => Model.ToList()[Model.Count() - 1].RemainingBalance)</b>
            </td>
            <td align="right">
                <b>@Html.DisplayFor(m => Model.ToList()[Model.Count() - 1].PercentageSpent)</b>
            </td>
            <td align="right">
                <b>@Html.DisplayFor(m => Model.ToList()[Model.Count() - 1].RemainingBalance)</b>
            </td>
            <td align="right">
                @if (Model.ToList()[Model.Count() - 1].CostProjection > 0)
                {
                    <b>@Html.DisplayFor(modelItem => Model.ToList()[Model.Count() - 1].CostProjection)</b>
                }
            </td>
            <td align="right">
                @if (Model.ToList()[Model.Count() - 1].Surplus < 0)
                {
                    <font color="red"><b>@Html.DisplayFor(modelItem => Model.ToList()[Model.Count() - 1].Surplus)</b></font>
                }
                else
                { 
                    <b>@Html.DisplayFor(modelItem => Model.ToList()[Model.Count() - 1].Surplus)</b>
                }
            </td>
        </tr>
        <tr class="gridheader">
            <th align="center">@Resources_frank.Global_String_Category</th>
            <th align="center">@Resources_frank.Budget_CategoryList_ProjectNo</th>
            <th align="center">@Resources_frank.Budget_CategoryList_Donor</th>
            <th align="center">@Resources_frank.Budget_ViewBudget_TotalBudget</th>
            <th align="center">@Resources_frank.Budget_ViewBudget_TotalCommitted</th>
            <th align="center">@Resources_frank.Budget_ViewBudget_TotalPosted</th>
            <th align="center">@Resources_frank.Budget_ViewBudget_RemainingFunds</th>
            <th align="center">% @Resources_frank.MasterBudget_MasterBudget_ActualSpent</th>
            <th align="center">@Resources_frank.MasterBudget_MasterBudget_FundsAvailable</th>
            <th align="center">@Resources_frank.MasterBudget_MasterBudget_ExpenditureProjection</th>
            <th align="center">@Resources_frank.MasterBudget_MasterBudget_ShortfallSurplus</th>
        </tr>
    @{int x = 0; int pjCount = 0; string rowClass = ""; }
    @for (int j = 0; j < Model.Count() - 1; j++)
    {
        if (x % 2 == 0) { rowClass = "grideven"; }
        if (x % 2 != 0) { rowClass = "gridodd"; }
        if (x >= 0) { x = x + 1; pjCount = Model.ToList()[j].Projects.Count; }
        <tr>
            <td rowspan="@pjCount" align="center" valign="middle" style="background-color: #FCD5B4;">
                <b>@Html.DisplayFor(modelItem => Model.ToList()[j].EntityBudgetCategory.Description)</b>
            </td>
            <td  style="background-color: #FCD5B4;">
                @Html.DisplayFor(modelItem => Model.ToList()[j].Projects[0].EntityProjectDonor.ProjectNumber)
            </td>
            <td  style="background-color: #FCD5B4;">
                @Html.DisplayFor(modelItem => Model.ToList()[j].Projects[0].EntityProjectDonor.Donor.Name)
            </td>
            <td align="right" style="background-color: #DCE6F1;">
                @Html.DisplayFor(modelItem => Model.ToList()[j].Projects[0].TotalBudget)
            </td>
            <td align="right" style="background-color: #DCE6F1;">
                @Html.DisplayFor(modelItem => Model.ToList()[j].Projects[0].TotalCommitted)
            </td>
            <td align="right" style="background-color: #DCE6F1;">
                @Html.DisplayFor(modelItem => Model.ToList()[j].Projects[0].TotalPosted)
            </td>
            <td align="right" style="background-color: #DCE6F1;">
                @Html.DisplayFor(modelItem => Model.ToList()[j].Projects[0].RemainingBalance)
            </td>
            <td align="right" style="background-color: #DCE6F1;">
                @Html.DisplayFor(modelItem => Model.ToList()[j].Projects[0].PercentageSpent)
            </td>
            <td rowspan="@pjCount" align="center" valign="middle" style="background-color: #DCE6F1; border-bottom-style: none;">
                <b>@Html.DisplayFor(modelItem => Model.ToList()[j].RemainingBalance)</b>
            </td>
            <td rowspan="@pjCount" align="center" valign="middle" style="background-color: #C4D79B; border-bottom-style: none;">
                @if (Model.ToList()[j].CostProjection > 0)
                {
                    <b>@Html.DisplayFor(modelItem => Model.ToList()[j].CostProjection)</b>
                }
            </td>
            <td rowspan="@pjCount" align="center" valign="middle" style="background-color: #C4D79B; border-bottom-style: none;">
                @if (Model.ToList()[j].CostProjection > 0)
                {
                    if (Model.ToList()[j].Surplus < 0)
                    {
                        <font color="red"><b>@Html.DisplayFor(modelItem => Model.ToList()[j].Surplus)</b></font>
                    }
                    else
                    { 
                        <b>@Html.DisplayFor(modelItem => Model.ToList()[j].Surplus)</b>
                    }
                }
            </td>
        </tr>
                for (int i = 1; i < Model.ToList()[j].Projects.Count; i++)
                { 
            <tr>
                <td style="background-color: #FCD5B4;">
                @Html.DisplayFor(modelItem => Model.ToList()[j].Projects[i].EntityProjectDonor.ProjectNumber)
                </td>
                <td style="background-color: #FCD5B4;">
                    @Html.DisplayFor(modelItem => Model.ToList()[j].Projects[i].EntityProjectDonor.Donor.Name)
                </td>
                <td align="right" style="background-color: #DCE6F1;">
                    @Html.DisplayFor(modelItem => Model.ToList()[j].Projects[i].TotalBudget)
                </td>
                <td align="right" style="background-color: #DCE6F1;">
                    @Html.DisplayFor(modelItem => Model.ToList()[j].Projects[i].TotalCommitted)
                </td>
                <td align="right" style="background-color: #DCE6F1;">
                    @Html.DisplayFor(modelItem => Model.ToList()[j].Projects[i].TotalPosted)
                </td>
                <td align="right" style="background-color: #DCE6F1;">
                    @Html.DisplayFor(modelItem => Model.ToList()[j].Projects[i].RemainingBalance)
                </td>
                <td align="right" style="background-color: #DCE6F1;">
                    @Html.DisplayFor(modelItem => Model.ToList()[j].Projects[i].PercentageSpent)
                </td>
            </tr>
                }
        <tr>
            <td colspan="3" align="right" style="background-color: #FCD5B4;">
                <b>@Html.DisplayFor(modelItem => Model.ToList()[j].EntityBudgetCategory.Description)</b>
            </td>
            <td align="right" style="background-color: #DCE6F1;">
                <b>@Html.DisplayFor(modelItem => Model.ToList()[j].TotalBudget)</b>
            </td>
            <td align="right" style="background-color: #DCE6F1;">
                <b>@Html.DisplayFor(modelItem => Model.ToList()[j].TotalCommitted)
            </td>
            <td align="right" style="background-color: #DCE6F1;">
                <b>@Html.DisplayFor(modelItem => Model.ToList()[j].TotalPosted)
            </td>
            <td align="right" style="background-color: #DCE6F1;">
                <b>@Html.DisplayFor(modelItem => Model.ToList()[j].RemainingBalance)
            </td>
            <td align="right" style="background-color: #DCE6F1;">
                <b>@Html.DisplayFor(modelItem => Model.ToList()[j].PercentageSpent)
            </td>
            <td style="background-color: #DCE6F1; border-top-style: none;">
               &nbsp; 
            </td>
            <td style="background-color: #C4D79B; border-top-style: none;">
               &nbsp; 
            </td>
            <td style="background-color: #C4D79B; border-top-style: none;">
               &nbsp; 
            </td>
        </tr>
        <tr>
            <td colspan="11">&nbsp;</td>
        </tr>
        
    }
    <tr><td colspan="6" align="center"><a href="/Reports/MasterBudget/Download/@ViewBag.CurrencyId" title="@Resources_frank.Budget_ViewBudget_DownloadExcelTitle" class="btn btn-primary">@Resources_frank.Budget_ViewBudget_DownloadExcel</a></td>
    <td colspan="5" align="center"><a href="/Reports/MasterBudget/Detail/@ViewBag.CurrencyId/@ViewBag.CountryProgrammeId" title="@Resources_frank.Budget_ViewBudget_DownloadPdf" class="btn btn-primary"  target="_blank">@Resources_frank.Budget_ViewBudget_DownloadPdf</a></td>
    </tr>    
    </table>